//      https://ac.nowcoder.com/acm/problem/233601




#include <iostream>
#include <queue>
#include <vector>
using namespace std;

typedef long long LL;

int main()
{
    int n;
    cin >> n;
    priority_queue<LL, vector<LL>, greater<LL> > h;
    while (n--)
    {
        LL x;
        cin >> x;
        h.push(x);
    }

    LL ans = 0;
    while (h.size() > 1)
    {
        LL a = h.top(); h.pop();
        LL b = h.top(); h.pop();
        h.push(a + b);
        ans += a + b;
    }
    cout << ans << endl;
    return 0;
}